import { getDetailInfo,getAddOrUpdateShopCart } from "@/api";
//封装游客身份模块uuid--->生成一个随机字符串（不能在变了）
import {getUUID} from '@/utils/uuid_token';

//Search的小仓库
const state = {
  detailInfo:{},
    //游客临时身份
    uuid_token:getUUID()
};
const mutations = {
  GETDEATILINFO(state,detailInfo){
    state.detailInfo = detailInfo
  }
};
const actions = {
  // 获取产品信息
  async getDetailInfo({commit},skuId){
    let result = await getDetailInfo(skuId)
    if(result.code==200){
      commit("GETDEATILINFO",result.data)
    }
  },
  // 将产品添加到购物车
  async addOrUpdateShopCart({commit},{skuId,skuNum}){
    let result = await getAddOrUpdateShopCart(skuId,skuNum)
  }
};
// 简化数据
const getters = {
  categoryView(state){
    return state.detailInfo.categoryView || {};
  },
  //简化产品信息的数据
  skuInfo(state) {
    return state.detailInfo.skuInfo || {};
  },
  //产品售卖属性的简化
  spuSaleAttrList(state) {
    return state.detailInfo.spuSaleAttrList || [];
  },
};

export default {
  state,
  mutations,
  actions,
  getters,
};
